home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_4 / cheby.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  725 b   |  31 lines  |  [MATF/MATL]

  1. function [C,X,Y] = cheby(fun,n,a,b)
  2. % [C] = cheby(fun,n)
  3. % [C,X,Y] = cheby(fun,n)
  4. % [C,X,Y] = cheby(fun,n,a,b)
  5. % Construction of the collocation polynomial.
  6. % The method is Chebyshev interpolation.
  7. % fun is the 'string function', input.
  8. % n is the degree, input.
  9. % a is the left  endpoint, input.
  10. % b is the right endpoint, input.
  11. % C is the coefficient list for the polynomial, output.
  12. % X are the abscissas, output.
  13. % Y are the ordinates, output.
  14. if nargin==2, a=-1; b=1; end
  15. d = pi/(2*n+2);
  16. C = zeros(1,n+1);
  17. for k=1:n+1,
  18.   X(k) = cos((2*k-1)*d);
  19. end
  20. X = (b-a)*X/2+(a+b)/2;
  21. x = X;
  22. Y = eval(fun);
  23. for k = 1:n+1,
  24.   z = (2*k-1)*d;
  25.   for j = 1:n+1,
  26.     C(j) = C(j) + Y(k)*cos((j-1)*z);
  27.   end
  28. end
  29. C = 2*C/(n+1);
  30. C(1) = C(1)/2;
  31.